<template>
	<view class="mainpadding2">
		<view class="mainpadding_top ffffff radius flexbetween">
			<view class="main_size bold hei_text">標題</view>
			<input type="text" placeholder="請輸入標題" v-model="name" class="textright">
		</view>
		<view class="mainpadding_top ffffff radius flexbetween" @click="calendarshow=true">
			<view class="main_size bold hei_text">選擇日期</view>
			<u-icon name="arrow-right" color="#333" size="14"></u-icon>
		</view>
		<view class="flexleft flex-wrap">
			<view class="xiaohui margin_top2 margin_right1 riqik" v-for="item in defaultDateMultiple" :key="item">{{item}}</view>
		</view>
		<view class="mainpadding_top ffffff radius flexbetween">
			<view class="main_size bold hei_text">車泊</view>
			<input type="text" placeholder="請輸入車泊價格" v-model="cb_price" class="textright">
		</view>
		<view class="mainpadding_top ffffff radius flexbetween">
			<view class="main_size bold hei_text">搭帳</view>
			<input type="text" placeholder="請輸入搭帳價格" v-model="dz_price" class="textright">
		</view>
		<view class="mainpadding_top ffffff radius flexbetween">
			<view class="main_size bold hei_text">夜衝</view>
			<input type="text" placeholder="請輸入夜衝價格" v-model="yc_price" class="textright">
		</view>
		<view class="mainpadding_top ffffff radius flexbetween">
			<view class="main_size bold hei_text">休息</view>
			<input type="text" placeholder="請輸入休息價格" v-model="xx_price" class="textright">
		</view>
		<view class="mainpadding_top ffffff radius flexbetween">
			<view class="main_size bold hei_text">住宿</view>
			<input type="text" placeholder="請輸入住宿價格" v-model="zs_price" class="textright">
		</view>
		<view class="posibottom mainpadding2">
			<view class="submitbtn" @click="submit">確定</view>
		</view>
		<u-calendar confirmText="確認" :defaultDate="defaultDateMultiple" title="選擇日期" startText="開始" :monthNum="30"
			endText="結束" :show="calendarshow" mode="multiple" @close="calendarshow=false" color="#fbb826"
			@confirm="calendarconfirm"></u-calendar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				listid: "",
				calendarshow: false, //日曆選擇器
				defaultDateMultiple: [],
				name: "",
				cb_price: "",
				dz_price: "",
				yc_price: "",
				xx_price: "",
				zs_price: "",
				issubmit:false
			}
		},
		onLoad(options) {
			if (options.id) {
				this.listid = options.id
				uni.setNavigationBarTitle({
					title:"編輯節假日價格"
				})
				this.getDetail()
			}
		},
		methods: {
			getDetail(){
				this.http.request("/api/hotel/jjrpriceDetail", 'GET', {
					id:this.listid
				}).then(res=>{
					let data = res.data
					this.name=data.name
					this.defaultDateMultiple=data.date_time_text
					this.cb_price=data.cb_price
					this.dz_price=data.dz_price
					this.yc_price=data.yc_price
					this.xx_price=data.xx_price
					this.zs_price=data.zs_price
				})
			},
			async submit(){
				if(this.name==""){
					this.http.toast("請輸入名稱")
					return false
				}
				if(this.defaultDateMultiple.length==0){
					this.http.toast("請選擇日期")
					return false
				}
				if(this.cb_price==""){
					this.http.toast("請輸入車泊價格")
					return false
				}
				if(this.dz_price==""){
					this.http.toast("請輸入搭帳價格")
					return false
				}
				if(this.yc_price==""){
					this.http.toast("請輸入夜衝價格")
					return false
				}
				if(this.xx_price==""){
					this.http.toast("請輸入休息價格")
					return false
				}
				if(this.zs_price==""){
					this.http.toast("請輸入住宿價格")
					return false
				}
				if(this.issubmit) return
				this.issubmit = true
				let datamsg = {
					shop_id:uni.getStorageSync("shop_id"),
					name:this.name,
					cb_price: this.cb_price,
					dz_price: this.dz_price,
					yc_price: this.yc_price,
					xx_price: this.xx_price,
					zs_price: this.zs_price,
					date_time:this.defaultDateMultiple.join()
				}
				let url = "/api/hotel/addJjrprice"
				if(this.listid){
					url = "/api/hotel/editJjrprice"
					this.$set(datamsg,"id",this.listid)
				}
				uni.showLoading({
					mask:true,
					title:"請稍後"
				})
				let res = await this.http.request(url, 'POST', datamsg)
				uni.hideLoading()
				if(res.code==1){
					this.http.toast(res.msg)
					setTimeout(()=>{
						uni.navigateBack(1)
					},1000)
				}else{
					this.issubmit = false
					this.http.toast(res.msg)
				}
			},
			calendarconfirm(e) {
				console.log(e);
				this.defaultDateMultiple = e
				this.calendarshow = false
			},
		}
	}
</script>

<style lang="scss" scoped>
	.riqik{
		border: 1rpx solid #999;
		padding: 5rpx 10rpx;
	}
</style>